package com.openatc.agent.service;

import com.google.gson.Gson;
import com.openatc.comm.data.MessageData;
import com.openatc.core.model.RESTRet;
import com.openatc.core.util.RESTRetUtils;

import java.util.logging.Logger;

/**
 * @Classname GenericGetRequest
 * @Description
 * @Date 2022/7/19 13:14
 * @Created by panleilei
 */
public abstract class GenericMsgStrategy implements MsgPreStrategy,MsgPostStrategy{
    protected Gson gson = new Gson();
    protected static Logger logger = Logger.getLogger(GenericMsgStrategy.class.toString());
    protected String dataSource = "Cache";

    /**
     * 在向信号机发送请求前预处理消息
     * 适配器默认实现，返回空数据，继续向信号机请求
     * @param requestData
     * @return
     */
    @Override
    public RESTRet preProcess(MessageData requestData) {
        return RESTRetUtils.successObj(null);
    }

    /**
     * 对成功的get-request请求做后置处理
     * 适配器默认实现，返回空数据，会将原始的应答数据应答给请求方
     * @param requestData
     * @param responseData
     * @return
     */
    @Override
    public RESTRet successGetProcess(MessageData requestData, RESTRet responseData) {
        return RESTRetUtils.successObj(null);
    }

    /**
     * 对失败的get-request请求做后置处理
     * 适配器默认实现，返回空数据，会将原始的应答数据应答给请求方
     * @param requestData
     * @param responseData
     * @return
     */
    @Override
    public RESTRet failureGetProcess(MessageData requestData, RESTRet responseData) {
        return RESTRetUtils.successObj(null);
    }

    /**
     * 对成功的set-request请求做后置处理
     * @param requestData
     * @param responseData
     * @return
     */
    @Override
    public RESTRet successSetProcess(MessageData requestData, RESTRet responseData) {
        return RESTRetUtils.successObj(null);
    }

    /**
     * 对失败的set-request请求做后置处理
     * @param requestData
     * @param responseData
     * @return
     */
    @Override
    public RESTRet failureSetProcess(MessageData requestData, RESTRet responseData) {
        return RESTRetUtils.successObj(null);
    }


    public enum FieldName {
        PHASE_COUNT("phase_count"),
        PATTERN_COUNT("pattern_count"),
        PLAN_COUNT("plan_count"),
        DATE_COUNT("date_count"),
        VEH_LAMP_COUNT("veh_lamp_count"),
        PED_LAMP_COUNT("ped_lamp_count"),
        OVERLAP_COUNT("overlap_count"),
        ;

        private String name;

        FieldName(String name) {
            this.name = name;
        }
    }
}
